// 发送请求
function getUserInfo() {
  $.ajax({
    url:'/my/user/userinfo',
    success:function (res) {
      console.log(res);
      if (res.status === 0) {
        // 1.处理 欢迎词
        let name = res.data.nickname || res.data.username ;
        $('.username').text(name);
        // 2.处理头像
        if (res.data.user_pic) {
          $('.layui-nav-img').attr('src',res.data.user_pic).show();
          $('.text-avatar').hide();
        } else {
          let first = res.data.username.substring(0,1).toUpperCase();
          $('.text-avatar').text(first).css('display','inline-block');
        }
      }
    }
  })
};
getUserInfo();
// 退出登陆
$('#logout').on('click',function () {
  layer.confirm('确定退出吗？', {icon: 3, title:'提示'}, function(index){
    //点击确定后，函数执行
    localStorage.removeItem('token');
    location.href = './login.html';
    //关闭弹出框
    layer.close(index);
  });
})